home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_wrappers.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  11.8 KB  |  436 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Help Control functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 2nd April 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new ad_settings();
  26.  
  27.  
  28. class ad_settings {
  29.  
  30.     var $base_url;
  31.  
  32.     function ad_settings() {
  33.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  34.  
  35.         switch($IN['code'])
  36.         {
  37.             case 'wrapper':
  38.                 $this->list_wrappers();
  39.                 break;
  40.                 
  41.             case 'add':
  42.                 $this->do_form('add');
  43.                 break;
  44.                 
  45.             case 'edit':
  46.                 $this->do_form('edit');
  47.                 break;
  48.                 
  49.             case 'doadd':
  50.                 $this->save_wrapper('add');
  51.                 break;
  52.                 
  53.             case 'doedit':
  54.                 $this->save_wrapper('edit');
  55.                 break;
  56.                 
  57.             case 'remove':
  58.                 $this->remove();
  59.                 break;
  60.                 
  61.             case 'export':
  62.                 $this->export();
  63.             
  64.             //-------------------------
  65.             default:
  66.                 $this->list_wrappers();
  67.                 break;
  68.         }
  69.         
  70.     }
  71.     
  72.     function export()
  73.     {
  74.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  75.         
  76.         if ($IN['id'] == "")
  77.         {
  78.             $ADMIN->error("You must specify an existing wrapper ID, go back and try again");
  79.         }
  80.         
  81.         //+-------------------------------
  82.         
  83.         $DB->query("SELECT * from ibf_templates WHERE tmid='".$IN['id']."'");
  84.         
  85.         if ( ! $row = $DB->fetch_row() )
  86.         {
  87.             $ADMIN->error("Could not query the information from the database");
  88.         }
  89.         
  90.         //+-------------------------------
  91.         
  92.         $archive_dir = $INFO['base_dir']."/archive_out";
  93.         
  94.         require $root_dir."sources/lib/tar.php";
  95.         
  96.         if (!is_dir($archive_dir))
  97.         {
  98.             $ADMIN->error("Could not locate $archive_dir, is the directory there?");
  99.         }
  100.         
  101.         if (!is_writeable($archive_dir))
  102.         {
  103.             $ADMIN->error("Cannot write in $archive_dir, CHMOD via FTP to 0755 or 0777 to enable this script to write into it. IBF cannot do this for you");
  104.         }
  105.         
  106.         //+-------------------------------
  107.         // Attempt to copy the files to the
  108.         // working directory...
  109.         //+-------------------------------
  110.         
  111.         $l_name = preg_replace( "/\s{1,}/", "_", $row['name'] );
  112.         
  113.         $file_name = "wrap-".$l_name.".html";
  114.         
  115.         $row['template'] = preg_replace("/\r/", "\n", $row['template'] );
  116.         
  117.         $FH = fopen($archive_dir."/".$file_name, 'w');
  118.         fwrite($FH, $row['template'], strlen($row['template']));
  119.         fclose($FH);
  120.         
  121.         $ADMIN->done_screen("Wrapper Export Created<br><br>You can download the html resource <a href='archive_out/$file_name' target='_blank'>here</a>", "Manage Board Wrappers", "act=wrap" );
  122.         
  123.         
  124.     }
  125.     
  126.     
  127.     //-------------------------------------------------------------
  128.     // REMOVE WRAPPERS
  129.     //-------------------------------------------------------------
  130.     
  131.     function remove()
  132.     {
  133.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  134.         
  135.         //+-------------------------------
  136.         
  137.         
  138.         if ($IN['id'] == "")
  139.         {
  140.             $ADMIN->error("You must specify an existing wrapper ID, go back and try again");
  141.         }
  142.         
  143.         $DB->query("DELETE FROM ibf_templates WHERE tmid='".$IN['id']."'");
  144.         
  145.         $std->boink_it($SKIN->base_url."&act=wrap");
  146.             
  147.         exit();
  148.         
  149.         
  150.     }
  151.     
  152.     
  153.     
  154.     //-------------------------------------------------------------
  155.     // ADD / EDIT WRAPPERS
  156.     //-------------------------------------------------------------
  157.     
  158.     function save_wrapper( $type='add' )
  159.     {
  160.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  161.         
  162.         //+-------------------------------
  163.         
  164.         if ($type == 'edit')
  165.         {
  166.             if ($IN['id'] == "")
  167.             {
  168.                 $ADMIN->error("You must specify an existing wrapper ID, go back and try again");
  169.             }
  170.         }
  171.         
  172.         if ($IN['name'] == "")
  173.         {
  174.             $ADMIN->error("You must specify a name for this wrapper");
  175.         }
  176.         
  177.         if ($IN['template'] == "")
  178.         {
  179.             $ADMIN->error("You can't have an empty template, can you?");
  180.         }
  181.         
  182.         $tmpl = preg_replace( "!</textarea>!", "/textarea>", stripslashes($HTTP_POST_VARS['template']) );
  183.         
  184.         if ( ! preg_match( "/<% BOARD %>/", $tmpl ) )
  185.         {
  186.             $ADMIN->error("You cannot remove the <% BOARD %> tag silly!");
  187.         }
  188.         
  189.         if ( ! preg_match( "/<% COPYRIGHT %>/", $tmpl ) )
  190.         {
  191.             $ADMIN->error("You cannot remove the <% COPYRIGHT %> tag silly!");
  192.         }
  193.         
  194.         $barney = array( 'name'     => stripslashes($HTTP_POST_VARS['name']),
  195.                          'template' => $tmpl
  196.                        );
  197.                        
  198.         if ($type == 'add')
  199.         {
  200.             $db_string = $DB->compile_db_insert_string( $barney );
  201.             
  202.             $DB->query("INSERT INTO ibf_templates (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")");
  203.             
  204.             $std->boink_it($SKIN->base_url."&act=wrap");
  205.             
  206.             exit();
  207.             
  208.         }
  209.         else
  210.         {
  211.             $db_string = $DB->compile_db_update_string( $barney );
  212.             
  213.             $DB->query("UPDATE ibf_templates SET $db_string WHERE tmid='".$IN['id']."'");
  214.             
  215.             $ADMIN->done_screen("Wrapper updated", "Manage Board Wrappers", "act=wrap" );
  216.         }
  217.         
  218.         
  219.     }
  220.     
  221.     //-------------------------------------------------------------
  222.     // ADD / EDIT WRAPPERS
  223.     //-------------------------------------------------------------
  224.     
  225.     function do_form( $type='add' )
  226.     {
  227.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  228.         
  229.         //+-------------------------------
  230.         
  231.         if ($IN['id'] == "")
  232.         {
  233.             $ADMIN->error("You must specify an existing wrapper ID, go back and try again");
  234.         }
  235.         
  236.         $DB->query("SELECT * from ibf_templates WHERE tmid='".$IN['id']."'");
  237.         
  238.         if ( ! $row = $DB->fetch_row() )
  239.         {
  240.             $ADMIN->error("Could not query the information from the database");
  241.         }
  242.         
  243.         if ($type == 'add')
  244.         {
  245.             $code = 'doadd';
  246.             $button = 'Create Wrapper';
  247.             $row['name'] = $row['name'].".2";
  248.         }
  249.         else
  250.         {
  251.             $code = 'doedit';
  252.             $button = 'Edit Wrapper';
  253.         }
  254.         
  255.         //+-------------------------------
  256.     
  257.         $ADMIN->page_detail = "You may use HTML fully when adding or editing wrappers.";
  258.         $ADMIN->page_title  = "Manage Board Wrappers";
  259.         
  260.         //+-------------------------------
  261.         
  262.         $ADMIN->html .= $SKIN->js_no_specialchars();
  263.         
  264.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , $code      ),
  265.                                                   2 => array( 'act'   , 'wrap'      ),
  266.                                                   3 => array( 'id'    , $IN['id']   ),
  267.                                          ), "theAdminForm", "onSubmit=\"return no_specialchars('wrapper')\""      );
  268.                                          
  269.         //+-------------------------------
  270.         
  271.         $SKIN->td_header[] = array( " "  , "20%" );
  272.         $SKIN->td_header[] = array( " "  , "80%" );
  273.  
  274.         //+-------------------------------
  275.         
  276.         $row['template'] = preg_replace( "/\/textarea>/", "</textarea>", $row['template'] );  // Stop html killing the text area
  277.         
  278.         $ADMIN->html .= $SKIN->start_table( $button );
  279.         
  280.         $ADMIN->html .= $SKIN->add_td_row( array( 
  281.                                                     "Wrapper Title",
  282.                                                     $SKIN->form_input('name', $row['name']),
  283.                                          )      );
  284.                                          
  285.         $ADMIN->html .= $SKIN->add_td_row( array( 
  286.                                                     "Content",
  287.                                                     $SKIN->form_textarea('template', $row['template'], "60", "15"),
  288.                                          )      );
  289.                                                  
  290.         $ADMIN->html .= $SKIN->end_form($button);
  291.                                          
  292.         $ADMIN->html .= $SKIN->end_table();
  293.         
  294.         //+-------------------------------
  295.         //+-------------------------------
  296.         
  297.         $ADMIN->output();
  298.         
  299.         
  300.     }
  301.     
  302.     //-------------------------------------------------------------
  303.     // SHOW WRAPPERS
  304.     //-------------------------------------------------------------
  305.     
  306.     function list_wrappers()
  307.     {
  308.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  309.         
  310.         $form_array = array();
  311.     
  312.         $ADMIN->page_detail = "You may add/edit and remove the board wrapper templates.<br><br>Board wrapper refers to the main board template which allows additional HTML to be added to the header and footer of the board";
  313.         $ADMIN->page_title  = "Manage Board Wrappers";
  314.         
  315.         //+-------------------------------
  316.         
  317.         $SKIN->td_header[] = array( "Title"        , "40%" );
  318.         $SKIN->td_header[] = array( "Allocation"   , "30%" );
  319.         $SKIN->td_header[] = array( "Export"       , "10%" );
  320.         $SKIN->td_header[] = array( "Edit"         , "10%" );
  321.         $SKIN->td_header[] = array( "Remove"       , "10%" );
  322.         
  323.         //+-------------------------------
  324.         
  325.         $DB->query("SELECT DISTINCT(w.tmid), w.name, s.sname from ibf_templates w, ibf_skins s WHERE s.tmpl_id=w.tmid ORDER BY w.name ASC");
  326.         
  327.         $used_ids = array();
  328.         $show_array = array();
  329.         
  330.         if ( $DB->get_num_rows() )
  331.         {
  332.         
  333.             $ADMIN->html .= $SKIN->start_table( "Current Wrappers In Use" );
  334.             
  335.             while ( $r = $DB->fetch_row() )
  336.             {
  337.             
  338.                 $show_array[ $r['tmid'] ] .= stripslashes($r['sname'])."<br>";
  339.             
  340.                 if ( in_array( $r['tmid'], $used_ids ) )
  341.                 {
  342.                     continue;
  343.                 }
  344.                 
  345.                 $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['name'])."</b>",
  346.                                                           "<#X-{$r['tmid']}#>",
  347.                                                           "<center><a href='".$SKIN->base_url."&act=wrap&code=export&id={$r['tmid']}'>Export</a></center>",
  348.                                                           "<center><a href='".$SKIN->base_url."&act=wrap&code=edit&id={$r['tmid']}'>Edit</a></center>",
  349.                                                           "<i>Deallocate before removing</i>",
  350.                                                  )      );
  351.                                                    
  352.                 $used_ids[] = $r['tmid'];
  353.                 
  354.                 $form_array[] = array( $r['tmid'], $r['name'] );
  355.                 
  356.             }
  357.             
  358.             foreach( $show_array as $idx => $string )
  359.             {
  360.                 $string = preg_replace( "/<br>$/", "", $string );
  361.                 
  362.                 $ADMIN->html = preg_replace( "/<#X-$idx#>/", "$string", $ADMIN->html );
  363.             }
  364.             
  365.             $ADMIN->html .= $SKIN->end_table();
  366.         }
  367.         
  368.         if ( count($used_ids) > 0 )
  369.         {
  370.         
  371.             $DB->query("SELECT tmid, name FROM ibf_templates WHERE tmid NOT IN(".implode(",",$used_ids).")");
  372.         
  373.             if ( $DB->get_num_rows() )
  374.             {
  375.             
  376.                 $SKIN->td_header[] = array( "Title"  , "70%" );
  377.                 $SKIN->td_header[] = array( "Export" , "10%" );
  378.                 $SKIN->td_header[] = array( "Edit"   , "10%" );
  379.                 $SKIN->td_header[] = array( "Remove" , "10%" );
  380.             
  381.                 $ADMIN->html .= $SKIN->start_table( "Current Unallocated Wrappers" );
  382.                 
  383.                 $ADMIN->html .= $SKIN->js_checkdelete();
  384.                 
  385.                 
  386.                 while ( $r = $DB->fetch_row() )
  387.                 {
  388.                     
  389.                     $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['name'])."</b>",
  390.                                                               "<center><a href='".$SKIN->base_url."&act=wrap&code=export&id={$r['tmid']}'>Export</a></center>",
  391.                                                               "<center><a href='".$SKIN->base_url."&act=wrap&code=edit&id={$r['tmid']}'>Edit</a></center>",
  392.                                                               "<center><a href='javascript:checkdelete(\"act=wrap&code=remove&id={$r['tmid']}\")'>Remove</a></center>",
  393.                                                      )      );
  394.                                                      
  395.                     $form_array[] = array( $r['tmid'], $r['name'] );
  396.                                                        
  397.                 }
  398.                 
  399.                 $ADMIN->html .= $SKIN->end_table();
  400.             }
  401.         }
  402.         
  403.         //+-------------------------------
  404.         //+-------------------------------
  405.         
  406.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'add'     ),
  407.                                                   2 => array( 'act'   , 'wrap'    ),
  408.                                          )      );
  409.         
  410.         $SKIN->td_header[] = array( " "  , "40%" );
  411.         $SKIN->td_header[] = array( " "  , "60%" );
  412.         
  413.         $ADMIN->html .= $SKIN->start_table( "Create New Wrapper" );
  414.             
  415.         //+-------------------------------
  416.         
  417.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Base new wrapper on...</b>" ,
  418.                                                     $SKIN->form_dropdown( "id", $form_array)
  419.                                  )      );
  420.         
  421.         $ADMIN->html .= $SKIN->end_form("Create new wrapper");
  422.                                          
  423.         $ADMIN->html .= $SKIN->end_table();
  424.         
  425.         //+-------------------------------
  426.         //+-------------------------------
  427.         
  428.         $ADMIN->output();
  429.     
  430.     }
  431.     
  432.     
  433. }
  434.  
  435.  
  436. ?>